// TODO LRU缓存结构  
// [https://www.nowcoder.com/practice/e3769a5f49894d49b871c09cadd13a61?tpId=117&&tqId=1006010]
function LRU(operators = [], k) {
    let { length } = operators;
    let map = new Map();
    let result = [];
    for (let i = 0; i < length; i++) {
        let [op, key, value] = operators[i];
        if (op === 1) {
            if (map.size >= k) {
                map.delete(map.keys().next().value)
                map.set(key, value);
            } else {
                //* 如果有的话先删除，保证是最新的，位置在最后面 
                if (map.has(key)) {
                    map.delete(key)
                }
                map.set(key, value)
            }
        } else if (op === 2) {
            if (!map.has(key)) {
                result.push(-1)
            } else {
                let value = map.get(key);
                result.push(value);
                map.delete(key);
                map.set(key, value)
            }
        }
    }
    return result
}
console.log(LRU([
    [1, 1, 1],
    [1, 2, 2],
    [1, 3, 2],
    [2, 1],
    [1, 4, 4],
    [2, 2]
], 3))